package com.dongdongshop.mq;

import com.dongdongshop.service.ItemPageService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

// 默认生效  我们的对象需要在容器中
@Component
// 实现 mq 的监听器 里面有一个泛型是我们消息的类型
// 需要指定消费的 topic 以及我们的消费者组
@RocketMQMessageListener(topic = "springboot-topic",consumerGroup = "my_mq")
public class RocketMQConsumer implements RocketMQListener<String []> {

    @Autowired
    private ItemPageService itemPageService;

    @Override
    public void onMessage(String[] strings) {
        System.out.println(111);
        for (String string : strings) {
            System.out.println("111"+string);
            itemPageService.createPage(Long.parseLong(string));
        }
    }
}
